 /***************************************************************************
 *   Copyright (C) 2010 by ZhangShine , All Rights Reserved                                  
 *   zhangshine0125@gmail.com                                              
 *                                                                         
 *   This program is free software; you can redistribute it and/or modify  
 *   it under the terms of the GNU General Public License as published by  
 *   the Free Software Foundation; either version 2 of the License, or     
 *   (at your option) any later version.                                   
 *                                                                         
 *   This program is distributed in the hope that it will be useful,       
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
 *   GNU General Public License for more details.                          
 *                                                                         
 *   You should have received a copy of the GNU General Public License     
 *   along with this program; if not, write to the                         
 *   Free Software Foundation, Inc.,                                       
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             
 ***************************************************************************/

#ifndef SINAWEIBO_H
#define SINAWEIBO_H

#include <QObject>
#include <QIcon>
#include <QtNetwork>
#include "account.h"
#include "sinaservices.h"
#include "status.h"
#include "configuration.h"
#include "oauth.h"

/*! \class SinaWeibo
 * \brief 微博信息处理与显示
 *
 *
 */
class SinaWeibo : public QObject
{
    Q_OBJECT
public:
    SinaWeibo(Account* account);
    ~SinaWeibo();
    bool verifyCredentials();
    QIcon getProfileIcon(const QString &urlString);
public:
    QString getFriendsTimeline( qint64 sinceId=0, qint64 maxId=0, int count=20, \
                            int page=1, int baseApp=0, int feature=0);
    QString getMentions(qint64 sinceId=0, qint64 maxId=0, int count=20, int page=1);
    QString getUserTimeline(qint64 userId=0, int count=20, int page=1, int baseApp=0, int feature=0 );
    QString getUserTimelineByScreenName(QString screenName, int count=20, int page=1, int baseApp=0, int feature=0);
    QString getFavorites(int page=1);
    QString getCommentTimeline(qint64 sinceId=0, qint64 maxId=0, int count=20, int page=1);
    QString getDirectMessage(qint64 sinceId=0, qint64 maxId=0, int count=20, int page=1);
    QString getEmotions();
    QString getUnread(QString sinceId);
    QString getStatusCountsByJson(QList<Status> &statusList);
    QString statusTextFormat(QString statusText);
    QString timeFormatHtml(QDateTime datetime);
    QString getCommentsList(QString id, int page=1, int count=20);
    
public:    
    QString homePageStatusToHtml(const QList<Status> &statusList, const QMap<QString,Status> &retwStatusMap);
    QString atMePageStatusToHtml(const QList<Status> &statusList, const QMap<QString,Status> &retwStatusMap);
    QString userWeiboPageStatusToHtml(const QList<Status> &statusList, const QMap<QString,Status> &retwStatusMap);
    QString favoritePageStatusToHtml(const QList<Status> &statusList, const QMap<QString,Status> &retwStatusMap);
    QString commentPageStatusToHtml(const QList<Status> &statusList, const QMap<QString,Status> &retwStatusMap);
    QString directMessagePageStatusToHtml(const QList<Status> &statusList);
    QString commentsListToHtml(const QList<Status> &statusList);
    QString statusToHtmlForNotifier(Status &status, Status &retwStatus);
    QString statusToHtmlForNotifier(Status &status);
            
    void initHomePageStatus();
    void initAtMePageStatus();
    void initUserWeiboPageStatus();
    void initFavoritePageStatus();
    void initCommentPageStatus();
    void initDirectMessagePageStatus();
    
    void initEmotions();
    int sendStatusWithoutPicture(QString statusContent);
    int sendStatusWithPicture(QString statusContent, QByteArray pictureInByteArray, QString fileName);
    int repost(QString id, QString status);
    int commentStatus(QString id, QString status);
    int addFavorite(QString id);
    int deleteFavorite(QString id);
    int deleteStatus(QString id);
    void getUnreadInfo(int &statusUnread, int &atMeMentionsUnread, 
                          int &commentsUnread, int &directMessageUnread, int &newFollower);
    int resetCount(int type);
    int replyComment(QString cid, QString id, QString statusText);
    int sendDirectMessage(QString uid, QString statusText);
    
signals:

public slots:
    
private:
    Account *account;
    SinaServices *servicesInstance;
    Configuration *conf;
    QString basicAuthInfo;
    QString contentFrame;
private:
    void setBasicAuth(QNetworkRequest &request);
    void setOAuthAuthorize( QNetworkRequest &request, OAuth::HttpMethod httpMethod, QString url, QMap<QString,QString> &params);

};

#endif // SINAWEIBO_H
